package com.acme.bankapp.service.bank;

import com.acme.bankapp.domain.bank.*;

import java.util.Random;

/**
 * Created by anton on 8/18/14.
 */
public class BankApplication {
    public static void createAccounts(Bank bank) {
        Random random = new Random();
        for (int i=0; i<bank.getMaxClients()/2; i++) {
            BankService.addClient(bank, new Client(
                    "Client",
                    Gender.MALE,
                    new SavingsAccount(Math.round(random.nextDouble()*100))));
        }
        for (int i=bank.getMaxClients()/2; i<bank.getMaxClients(); i++) {
            BankService.addClient(bank, new Client(
                    "Client",
                    Gender.MALE,
                    new CheckingAccount(Math.round(random.nextDouble()*100),
                            Math.round(random.nextDouble()*100))));
        }
    }

    public static void modifyBank(Bank bank) {
        Random random = new Random();
        for (Client c: bank.getClients()) {
            AbstractAccount acc = c.getAccount();
            acc.deposit(Math.round(random.nextDouble()*100));
            acc.withdraw(Math.round(random.nextDouble()*100));
        }

    }

    public static void printBalance(Bank bank) {
        for (Client c: bank.getClients()) {
            System.out.println("Client " + c + " has balance " + c.getAccount().getBalance());
        }
    }

    public static void main(String[] args) {
        Bank bank = new Bank();
        BankApplication.createAccounts(bank);
        BankApplication.modifyBank(bank);
        BankApplication.printBalance(bank);
        BankService.printMaximumAmountToWithdraw(bank);
    }
}
